class Person {
  private _name = "123";
  set name(new_value: string) {
    this._name = new_value;
  }
  get name() {
    return this._name;
  }
  public age = 18;

  //重载构造器
  public constructor(name: string, age: number);
  public constructor();
  constructor() {}

  public sing(): void {
    console.log(this.name, "sing");
  }
}

const p1 = new Person();
const p2 = new Person("mm", 18);
console.log(p1);
console.log(p2);
p1.name = "123";
p1.sing();

//语法糖
class PerSon2 {
  get Age() {
    return this.age;
  }
  //自动创建同名的属性
  constructor(public name: string, private age: number) {
    this.name = name;
  }
}
let p3 = new PerSon2("MARVIN", 18);
p3.name = "123";

//抽象类
abstract class Area {
  name: number = 10;
  abstract getArea(): number;
  getet() {
    console.log(12);
  }
}

class Rect extends Area {
  getArea() {
    return 100;
  }
}

function calArea(snap: Area) {
  return snap.getArea();
}
const area = calArea(new Rect());
console.log(area);

//抽象类不能被实例化

class Dog {
  constructor(public name: string) {
    this.name = "dd";
  }
}

function sing(ani: Dog) {
  console.log(ani);
}

sing(new Dog("DD"));
sing({ name: "12" }); //不报错
sing(new PerSon2("123", 18)); //不报错
//鸭子类型检测：只要像鸭子 就通过检测
const dog: Dog = new PerSon2("dd", 18);

//类的类型
class Person3 {}

//参数要求是 一个可以new 的函数 也就是构造函数
function factory(ctor: new () => void) {}
factory(Person3); //类就是构造函数

interface ICollection<T> {
  data: Array<T>;
  length: number;
  [idx: number]: number;
  // new (): void;
}

// const Collection: ICollection<number> = () => {};
// Collection.data = [1, 2, 3, 4];
// Collection.length = 4;

// function iteratorCollection(collection: ICollection<number>) {
//   // new collection();
//   console.log(collection[0]);
// }
// iteratorCollection();

interface IIndexType {
  [bbb: string]: any;
  [aaa: number]: any;
}
const nums: IIndexType = ["1", 1, "1234"];
export {};
